package com.dc.aimc.common.mybatis.context;


/**
 * 租户ID上下文
 */
public class TenantContext {

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>() {
        /**
         * 设置默认的租户id
         */
        @Override
        protected String initialValue() {
            return "meijia";
        }
    };

    /**
     * 切换租户
     *
     * @param tenantId
     */
    public static void setTenantId(String tenantId) {
        contextHolder.set(tenantId);
    }

    /**
     * 获取租户id
     *
     * @return 租户id
     */
    public static String getTenantId() {
        return contextHolder.get();
    }

    /**
     * 重置租户
     */
    public static void clearTenantId() {
        contextHolder.remove();
    }

}
